<template>
  <div>
    <div>
      <div>
        <el-dropdown style="margin-left: 10px" @command="handleCommand" trigger="click">
  <span class="el-dropdown-link">
    类型选择<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
          <el-dropdown-menu slot="dropdown" >
            <el-dropdown-item command="0">全部</el-dropdown-item>
            <el-dropdown-item :command="item.id" v-for="item in reportTypes" :key="item.id">{{item.title}}</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <div>
        <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%">
          <el-table-column
              label="举报时间"
              width="180">
            <template slot-scope="scope">
              {{scope.row.createTime|formatTime}}
            </template>
          </el-table-column>
          <el-table-column
              prop="content"
              label="举报内容">
          </el-table-column>
          <el-table-column
              prop="rtype"
              label="板块">
          </el-table-column>
          <el-table-column
              prop="id"
              label="举报原因">
            <template slot-scope="scope">
              {{getCause(scope.row.id)}}
            </template>
          </el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              {{getState(scope.row.state)}}
            </template>
          </el-table-column>
          <el-table-column
              prop="address"
              label="操作">
            <template slot-scope="scope">
              <el-button v-if="scope.row.state==0" size="mini" @click="toDeal(scope.row)" type="primary">前往处理</el-button>
              <el-button v-else size="mini" @click="toDeal(scope.row)" type="success">查看详情</el-button>
            </template>

          </el-table-column>
        </el-table>
        <div style="float: right;margin-right: 130px" class="block">
          <el-pagination
              background
              hide-on-single-page
              @current-change="currentChange"
              layout="prev, pager, next"
              :current-page="page.current"
              :total="page.total"></el-pagination>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import {getReportList, getReportTypes, getDeal, getArchives} from "../../network/admin"
export default {
  name: "ComplaintApp",
  data(){
    return{
      content:'撒大苏打还是肯定会杀杀杀健康档案傻傻的数据库的哈手机电话撒大苏打和傻傻的接口文档和卫生健康',
      isDeal:0,
      loading:true,
      reportTypes:[],
      kindId:0,
      recruitment:{},
      page:{
      },
      map:''
    }
  },
  computed:{
    tableData(){
      return this.page.records
    },

  },
  created() {
    this.getData()
    getReportTypes()  //获取可选举报类型
        .then(res=>{
          console.log(res)
          this.reportTypes=res.data.extend.list
        })
  },
  methods:{
    async getUserName(type,uid){
      let res=await getArchives(type,uid)
      let data=res.data.extend.object
      let userName=data.studentName||data.companyName||data.universityName
      console.log(userName)
      return userName
    },
    getState(state){
      if(state==1){
        return '已通过'
      }else if(state==-1){
        return '未通过'
      }else {
        return '未处理'
      }
    },
    toDeal(row){
      let {rtype,id}=row
      if(rtype=='招聘'){
        this.$router.push({
          path:'recReDetails',
          query:{
            id
          }
        })
      }else {
        this.$router.push({
          path:'dynamicReDetails',
          query:{
            id
          }
        })
      }

    },
    handleCommand(command) {
      this.kindId=command;
      getReportList(this.kindId,this.page.current)
          .then(res=>{
            console.log(res)
            this.page=res.data.extend.page
            this.map=res.data.extend.map
          })
    },
    getCause(id){
      return this.map[id].title
    },
    getData(){
      getReportList(0,1)
          .then(res=>{
            console.log(res)
            this.loading=false
            this.page=res.data.extend.page
            this.map=res.data.extend.map
          })
    },
    currentChange(val){
      getReportList(this.kindId,val)
          .then(res=>{
            console.log(res)
            this.page=res.data.extend.page
            this.map=res.data.extend.map
          })
    },

  }
}
</script>

<style lang="stylus" scoped>
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}
.el-icon-arrow-down {
  font-size: 12px;
}
#describe
  width 100%
  box-sizing border-box
  display flex
  justify-content space-between
  padding 10px
  & h4
    text-decoration underline orange
    line-height 30px
.describe-list p
  font-size 15px
  color rgb(97,104,124)
  line-height 38px
.industrial-list p
  line-height 30px
  font-size 15px

</style>
